package com.jinyi.wwdeng.api_demo

import com.google.gson.Gson
import com.google.gson.GsonBuilder
import org.json.JSONObject
import java.util.TimeZone

/**
 * TODO: 注意点：
 * TODO: 1、所有请求头都加两个参数：appid、product，值传产品名大写，如：HENECREDIT
 * TODO: 2、仅业务请求头都加Content-Type参数，值传：text/plain
 *
 * TODO: implementation 'com.google.code.gson:gson:2.8.6'
 */
object TestHeneCredit {

    /**
     * 加密参数
     */
    private fun encryptParams(hashMap: HashMap<String, Any>) {
        val content = Gson().toJson(hashMap).trim()
        println("aes before：\n $content")

        val result = AESCryptUtil.encryptDefault(content)
        println("aes after：\n $result")
    }

    /**
     * 解密返回
     */
    private fun decryptResult(content: String) {
        val result = AESCryptUtil.decryptDefault(content)
        val resultJson = JSONObject(result)

        val gson = GsonBuilder().setPrettyPrinting().create()
        val json = gson.toJson(resultJson).toString()

        println("aes after：\n $json")
    }

    /**
     * 时区请求body
     */
    fun timezoneBody() {
        val hashMap: HashMap<String, Any> = hashMapOf<String, Any>().apply {
            put("p", "HENECREDIT")
            put("tz", TimeZone.getDefault().id.toString())
        }

        encryptParams(hashMap = hashMap)
    }

    /**
     * 时区请求返回
     */
    fun timezoneResult() {
        val content =
            "/XSlEgAdsSoDWwnayJx5pzBBwi+UBPRlbrnzxekzbKdM9UZHyLM3e5Ukbi9e4N7xVYlh+F716LJG8/wiOYZrTQ=="

        decryptResult(content = content)
    }

    /**
     * app配置请求body
     */
    fun appConfigBody() {
        val hashMap: HashMap<String, Any> = hashMapOf<String, Any>().apply {
            put("product", "HENECREDIT")
            put("path", "nm3ZSPlqNsJB6KvPTFB3IQ")


            /**
             *  api bean data class A
             *
             *  basic params
             *  business params
             *
             * BeanA
             * Gson().toJson()
             * AesUtil.en()
             * Http.post()
             * AesUtil.de()
             * page view model
             */



            put("firstName", "cccc")
            put("middleName", "ffff")
            put("path", "nm3ZSPlqNsJB6KvPTFB3IQ")
            put("path", "nm3ZSPlqNsJB6KvPTFB3IQ")
            put("path", "nm3ZSPlqNsJB6KvPTFB3IQ")
            put("path", "nm3ZSPlqNsJB6KvPTFB3IQ")
            put("path", "nm3ZSPlqNsJB6KvPTFB3IQ")
            put("path", "nm3ZSPlqNsJB6KvPTFB3IQ")
            put("path", "nm3ZSPlqNsJB6KvPTFB3IQ")
            put("path", "nm3ZSPlqNsJB6KvPTFB3IQ")

        }

        encryptParams(hashMap = hashMap)
    }

    /**
     * app配置请求返回
     */
    fun appConfigResult() {
        val content =
"1osRk5IOAs1xjINZTgwefVzmf6mRp72Kk8AOncJ9ewpRDyUQtTPZR6X/rNcg3jxHfnFMa5d3Opz0l8kGuIZa9aIFFbLbe7dJo1/haFVlFM9EJNeAmcyd8CNz+vw2GKwiJW2RB+JnvJ/jWcAjd8Piyus/mKoN1D+xLOwgFmdA+UGAx3yQqhjKjNPJNM3MkfcwE5ScZvza9IgDYSlODofaQQKv+h0/J+Ln6Z91W4JKdZhMEAKJTUG+NS8iUZsrgffCDvUDhjSMD3O6l2aJ0xfq7jgyV5BE+uLqRpQmJuZqOrjE3Ud/i1ETH8DAcR2uhWiPyoSJ9Kw8CBk9PTbVIxzdqqOZqQFTZNr+JhLqVQf0jwf9XJRBjCFHuFPbttGyIuw6eR8MZm0PWfmVML/zNeo0dRC3qb0tHlKxc+7vZj93CpmDtuCB/xp8l1zo9RIQg/rrX+tEIZaVOPSVNj7do6UfHV2HlDeFY0CMGg5uebbJYNa0xG6ehHUonQ+tep+SpRqsB16IThWFdTBlrH/hQl2NDaYc1GeIIZbG6Wq6Ah1CzgoFXtjMsODzVsMNiG/WzXVK+vE75bEoDn9Mbq2WQcylGbTMti7lgMe0CqxyYT4CZIAofYBuwG9goBS7ybQLkmCpihm2ay7Ll9TN+CCp9NBnm8EpiKXf84exKNiYyzeflYbkKnd3VkKL5PKQ0ACLZ287a2Kwx0K/4YAamEunwxd8eu38S0kIipH4qfeES3OHc4+WyAb49FJAyM2gsLxCGd615n6gyntAjAG5aV7VLfwp240EtBoQDAuTXhmbqlckLH4="

        decryptResult(content = content)
    }
}